// todo npm install vite-plugin-svg-icons -D 安装svg组件


import type { UserConfig, ConfigEnv } from 'vite';
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from "path";
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
// https://github.com/element-plus/unplugin-element-plus/blob/HEAD/README.zh-CN.md
// todo ElementPlus导入问题
// import ElementPlus from 'element-plus'
// import ElementPlus from 'unplugin-element-plus/vite'
export default defineConfig(({ command, mode } : ConfigEnv) : UserConfig => {

	// const env = loadEnv(mode, process.cwd(), '')
	console.log(command, mode);
	return {
		plugins: [vue(),
		AutoImport({
			resolvers: [ElementPlusResolver()],
		}),
		Components({
			resolvers: [ElementPlusResolver()],
		}),
		// ElementPlus({
		// 	useSource: true
		// })
		],
		publicDir: "public",
		base: "/",
		server: {
			open: false, // 是否自动在浏览器打开
			cors: true, // 允许跨域  8月更新
			port: 3033, // 端口号
			host: "0.0.0.0",
			// 禁用源映射以避免开发环境中的警告
			sourcemapIgnoreList: false,
			proxy: {
				"/api": {
					// 匹配请求路径，
					target: "http://127.0.0.1:5000",//正式域名
					changeOrigin: true,
					// secure: true, // 是否https接口
					ws: true, // 是否代理websockets
					rewrite: (path) => path,
					// rewrite: (path) => path.replace(/^\/api/, '') (看接口具体情况)
				},
			},
		},
		resolve: {
			alias: {
				"@": resolve(__dirname, "./src"),
				"components": resolve(__dirname, "./src/components"),
				"api": resolve(__dirname, "./src/api"),
			},
		},
		css: {
			// css预处理器
			preprocessorOptions: {
				scss: {
					// charset: false,
					additionalData: `@use "./src/assets/css/variable.scss" as *;`,
				},
			},
		},
		build: {
			outDir: 'dist',
			// 确保生产环境生成源映射
			sourcemap: true,
		},
		esbuild: {
			// 控制是否生成源映射
			sourcemap: true,
		}
	}

})
